﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace HossMvp.Core
{
    public class ViewManager : AbstractViewManager
    {
        public ViewManager()
        {
            this.Views = new List<AbstractView>();
        }

        public ViewManager(AbstractPresenter presenter)
        {
            this.Views = presenter.ViewManager.Views;
        }

        public override IEnumerable<AbstractView> Views { get; protected set; }

        public override AbstractView Create<T>(params object[] args)
        {
            var argsAug = new List<object>(args);
            argsAug.Insert(0, this);

            var view = (AbstractView)Activator.CreateInstance(typeof(T), argsAug.ToArray());
            Debug.Assert(view.Contents != null, "view.Contents != null");
            Debug.Assert(view.Manager == this, "view.Manager == this");

            // add to the list of views
            ((List<AbstractView>)this.Views).Add(view);

            return view;
        }

        public override void Remove(AbstractView view)
        {
            ((List<AbstractView>)this.Views).Remove(view);
        }
    }
}